<?php

	// TITLE: Project_expense_type AUTO MODEL
	// FILE: scaffolding/model/project_expense_type.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createProjectExpenseType = function($con, $projectExpenseType) {
		$sql = 'INSERT INTO project_expense_type (id, title, code, description) VALUES (';
		$sql .= $project_expense_type->getId() . ', ';
		$sql .= $project_expense_type->getTitle() . ', ';
		$sql .= $project_expense_type->getCode() . ', ';
		$sql .= $project_expense_type->getDescription() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readProjectExpenseType = function($con, $id) {
		$sql = 'SELECT * FROM project_expense_type WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$projectExpenseType = new ProjectExpenseType();
			$projectExpenseType->setId(result[0]);
			$projectExpenseType->setTitle(result[1]);
			$projectExpenseType->setCode(result[2]);
			$projectExpenseType->setDescription(result[3]);
		} else {
			$projectExpenseType = false;
		}
		return $projectExpenseType;
	};

	$updateProjectExpenseType = function($con, $projectExpenseType) {
		$sql = 'UPDATE project_expense_type SET ';
		$sql .= 'id = ' . $project_expense_type->getId() . ', ';
		$sql .= 'title = ' . $project_expense_type->getTitle() . ', ';
		$sql .= 'code = ' . $project_expense_type->getCode() . ', ';
		$sql .= 'description = ' . $project_expense_type->getDescription() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteProjectExpenseType = function($con, $id) {
		$sql = 'DELETE FROM project_expense_type WHERE id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listProjectExpenseType = function($con) {
		$sql = 'SELECT * FROM project_expense_type';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$projectExpenseTypes = array();
			while ($result = mysqli_fetch_array($results)) {
				$projectExpenseType = new ProjectExpenseType();
				$projectExpenseType->setId(result[0]);
				$projectExpenseType->setTitle(result[1]);
				$projectExpenseType->setCode(result[2]);
				$projectExpenseType->setDescription(result[3]);
				$projectExpenseTypes[] = projectExpenseType;
			}// end while
		} else {
			$projectExpenseTypes = false;
		}
		return $projectExpenseTypes;
	};

